const express = require('express');
const fs= require('fs')

const exceljs = require('exceljs')
const bodyParser = require('body-parser');
const file = 'error.xlsx';
const workbook = new exceljs.Workbook();
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.post('/error',async (req,res)=>{
    let {error,method}=req.body;
    error+=';\n'
    const errorTxt = `${new Date().toLocaleString()} ${method} ${error}`
     fs.appendFileSync('error.txt',errorTxt,'utf8')
    // await workbook.xlsx.readFile(file);
    // let worksheet = workbook.getWorksheet(1);
    // let lastRow = worksheet.lastRow;
    // let getRowInsert = worksheet.getRow(++(lastRow.number));
    // //项目名称
    // getRowInsert.getCell('A').value = '111'
    // // 时间
    // getRowInsert.getCell('B').value = new Date().toLocaleString();
    // // 错误信息
    // getRowInsert.getCell('C').value = error;
    // getRowInsert.commit();
    // workbook.xlsx.writeFile(file);
    res.send({msg:'success',code:0})
})
app.use(express.static('./'))
app.listen(5000,()=>{
    console.log(`server runing 5000`);
})